<?php

/**
 * cycletestcases actions.
 *
 * @package    tectesu
 * @subpackage cycletestcases
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class cycletestcasesActions extends sfActions
{
  
  public function executeCycleTestCaseById(sfWebRequest $request)
  {
     $this->cycleTestCase = new CycleTestcases();
    
     $this->testcaseListById = $this->cycleTestCase->getListTestSuiteById($request->getParameter('id'));
  }
  
  public function  executeListCycleTestCaseById(sfWebRequest $request){
    
    $this->id =  $request->getParameter('id');
    
    if (!$this->id)
    {
      $this->id = $this->getUser()->getAttribute("IdUser");
    }
    $this->cycleTestCase = new CycleTestcases();
    $this->cycletestcases_list = $this->cycleTestCase->getListTestSuiteById($this->id);
  }	
  
  public function executeIndex(sfWebRequest $request)
  {
    $this->cycletestcases_list = Doctrine::getTable('Cycletestcases')
      ->createQuery('a')
      ->execute();
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new CycleTestcasesForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post'));

    $this->form = new CycletestcasesForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($cycletestcases = Doctrine::getTable('CycleTestcases')->find(array($request->getParameter('idcycle'),
               $request->getParameter('idtestcase'),
               $request->getParameter('userid'))), sprintf('Object cycletestcases does not exist (%s).', array($request->getParameter('idcycle'),
               $request->getParameter('idtestcase'),
               $request->getParameter('userid'))));
    $this->form = new CycleTestcasesForm($cycletestcases);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post') || $request->isMethod('put'));
    $this->forward404Unless($cycletestcases = Doctrine::getTable('Cycletestcases')->find(array($request->getParameter('idcycle'),
               $request->getParameter('idtestcase'),
               $request->getParameter('userid'))), sprintf('Object cycletestcases does not exist (%s).', array($request->getParameter('idcycle'),
               $request->getParameter('idtestcase'),
               $request->getParameter('userid'))));
    $this->form = new CycletestcasesForm($cycletestcases);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($cycletestcases = Doctrine::getTable('Cycletestcases')->find(array($request->getParameter('idcycle'),
               $request->getParameter('idtestcase'),
               $request->getParameter('userid'))), sprintf('Object cycletestcases does not exist (%s).', array($request->getParameter('idcycle'),
               $request->getParameter('idtestcase'),
               $request->getParameter('userid'))));
    $cycletestcases->delete();

    $this->redirect('cycletestcases/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()));
    if ($form->isValid())
    {
      $cycletestcases = $form->save();

      $this->redirect('cycletestcases/edit?idcycle='.$cycletestcases['idcycle'].'&idtestcase='.$cycletestcases['idtestcase'].'&userid='.$cycletestcases['userid']);
    }
  }
}
